1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.lang3.text.translate;
19  
20  import static org.junit.Assert.assertTrue;
21  
22  import java.util.HashSet;
23  import java.util.Set;
24  
25  import org.junit.Test;
26  
27  /**
28   * Unit tests for {@link org.apache.commons.lang3.text.translate.EntityArrays}.
29   * @version $Id$
30   */
31  public class EntityArraysTest  {
32  
33      @Test
34      public void testConstructorExists() {
35          new EntityArrays();
36      }
37      
38      // LANG-659 - check arrays for duplicate entries
39      @Test
40      public void testHTML40_EXTENDED_ESCAPE(){
41          final Set<String> col0 = new HashSet<String>();
42          final Set<String> col1 = new HashSet<String>();
43          final String [][] sa = EntityArrays.HTML40_EXTENDED_ESCAPE();
44          for(int i =0; i <sa.length; i++){
45              assertTrue("Already added entry 0: "+i+" "+sa[i][0],col0.add(sa[i][0]));
46              assertTrue("Already added entry 1: "+i+" "+sa[i][1],col1.add(sa[i][1]));
47          }
48      }
49      
50     // LANG-658 - check arrays for duplicate entries
51      @Test
52      public void testISO8859_1_ESCAPE(){
53          final Set<String> col0 = new HashSet<String>();
54          final Set<String> col1 = new HashSet<String>();
55          final String [][] sa = EntityArrays.ISO8859_1_ESCAPE();
56          boolean success = true;
57          for(int i =0; i <sa.length; i++){
58              final boolean add0 = col0.add(sa[i][0]);
59              final boolean add1 = col1.add(sa[i][1]);
60              if (!add0) { 
61                  success = false;
62                  System.out.println("Already added entry 0: "+i+" "+sa[i][0]+" "+sa[i][1]);
63              }
64              if (!add1) {
65                  success = false;
66                  System.out.println("Already added entry 1: "+i+" "+sa[i][0]+" "+sa[i][1]);
67              }
68          }
69          assertTrue("One or more errors detected",success);
70      }
71      
72      
73  }